<template>
	<view class="margin-sm" style="margin-bottom: 100rpx;">

		<view>
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" />
			</view>

			<view v-if="list.length==0" class="margin-top-sm">
				<blues-empty img="msg" text="暂无数据">

				</blues-empty>
			</view>
			<view v-for="item in list" class="bg-white radius padding-sm margin-top-sm" style="">
				<view>
					{{item.content}}
				</view>

				<view
					style="display: flex;  justify-content: space-between;margin-top: 20rpx;font-size: 24rpx;color: #a3a3a3;">
					<view>{{item.status==1?'联系成功':'联系失败'}}</view>
					<view>{{formatterUserName(item.createBy)}}</view>
					<view>{{item.createTime}}</view>
				</view>
			</view>
		</view>


		<view style="width: 710rpx;position: fixed;bottom: 20px;">
			<button @click="addCommunication" type="primary" class="login-btn cu-btn block bg-blue lg round ">
				<vab-icon class="vab-icon phoneicon margin-lr-sm" :icon="['fas', 'comment-dots']"
					:style="{color:'#fff'}"></vab-icon>添加沟通记录</button>
		</view>

		<addCommunication @refresh="init" ref="addCommunication"></addCommunication>
	</view>
</template>

<script>
	import addCommunication from '@/pages/marketing/communication/addCommunication.vue'
	import {
		getById
	} from '@/api/marketing/communication'
	import {
		formatterUserName,
		getcommon
	} from '@/utils/common'


	export default {
		components: {
			addCommunication
		},
		data() {
			return {
				current: 0,
				items: ['沟通记录', '操作记录', '家长记录'],
				customerId: null,
				list: []
			}
		},
		onLoad(o) {
			this.customerId = o.customerId
			this.init()
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
					if (this.current == 0) {
						this.getList(1)
					}
					if (this.current == 1) {
						this.getList(2)
					}
					if (this.current == 2) {
						this.getList(4)
					}
				}
			},

			addCommunication() {
				this.$refs["addCommunication"].open(this.customerId);
			},
			formatterUserName(cellValue) {
				return formatterUserName(cellValue)
			},
			init() {
				this.getList(0)
			},
			async getList(type) {
				let {
					data
				} = await getById({
					customerId_EQ: this.customerId,
					type: type
				})

				this.list = data
			}
		}
	}
</script>

<style>

</style>